package com.cdshangpai.utils.offlinecache.casecache;

import android.util.Log;

import com.cdshangpai.photoapp.LogConfig;
import com.cdshangpai.utils.api.Api;
import com.cdshangpai.utils.db.beans.Case;
import com.cdshangpai.utils.log.LogUtil;
import com.cdshangpai.utils.offlinecache.DbVersion;
import com.cdshangpai.utils.offlinecache.base.BaseCacheProcessor;
import com.cdshangpai.utils.offlinecache.base.DataDownloader;
import com.cdshangpai.utils.offlinecache.base.query.CaseQuery;

import java.util.List;

//案例下载处理器
public class CaseCacheProcessor {
    private static CaseQuery caseQuery;
    Api api;


    /**
     * 初始化处理器
     */
    public CaseCacheProcessor()
    {
        api=new Api();
        caseQuery=new CaseQuery();
    }

    public boolean begin(List<DbVersion> cases)
    {
        DataDownloader dataDownloader=new DataDownloader() {
            @Override
            public List download(List ids) {
                return api.queryCase(ids);
            }
        };
        List<Case> localDatas=caseQuery.query();
        LogUtil.save("开始同步案例...");
        Log.i(LogConfig.logTag,"开始同步案例...");
        return new BaseCacheProcessor<Case>()
                .setDbQuery(caseQuery)
                .setDataDownloader(dataDownloader)
                .setLocalDatas(localDatas)
                .setServerVersion(cases)
                .forCase()
                .begin();
    }
}
